package com.jm3.riscar3.gui;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;
import javax.swing.JLabel;

import com.jm3.riscar3.core.Microcontroller;
import com.jm3.riscar3.exceptions.OutOfBoundsMemoryLocationException;



public class digitalKeyboard implements KeyListener{
	JFrame frame = new JFrame("Digital Keyboard");
	private int key;
	private Microcontroller mcu;
	private int memLoc;
	public void init(Microcontroller mcu, int memLoc) {
		this.mcu=mcu;
		this.memLoc=memLoc;
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JLabel comp=new JLabel("Type a number or a letter");
		comp.setFocusable(true);
		comp.addKeyListener(this);
		frame.add(comp);
		frame.setResizable(false);
		frame.pack();
		frame.setVisible(true);
	}
	@Override
	public void keyPressed(KeyEvent e) {
		
	}
	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		key=(int)e.getKeyChar();
		try {
			mcu.getMemory().writeToLocation(memLoc, key);
		} catch (OutOfBoundsMemoryLocationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		mcu.getCPU().getAcc().writeRegister(key);
		frame.setVisible(false);
		frame.dispose();
		
	}
	public int getCharValue() {
		// TODO Auto-generated method stub
		return key;
	}}
